package com.tiantianfresh.view.controller;

import com.tiantianfresh.model.pojo.AJAXResult;
import com.tiantianfresh.model.pojo.User;
import com.tiantianfresh.view.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @author FANGAO
 * @date 2021/11/28 - 下午 14:58
 */
@Controller
@RequestMapping("/register")
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    @ResponseBody
    @RequestMapping("/userRegister")
    public Object AjaxLogin(User user){
        AJAXResult result = new AJAXResult();
        user.setCreateTime(new Date());
        if(registerService.insert(user)){
            result.setSuccess(true);
            result.setData(user);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
    @ResponseBody
    @RequestMapping("/loginacctRegister")
    public Object loginacctRegister(String loginacct){
        AJAXResult result = new AJAXResult();
            result.setSuccess(registerService.selectLoginacct(loginacct));
        return result;
    }
    @ResponseBody
    @RequestMapping("/emailRegister")
    public Object emailRegister(String email){
        AJAXResult result = new AJAXResult();
        result.setSuccess(registerService.selectEmail(email));
        return result;
    }
}
